

import {getCheckNewVersionStatusCallback} from "./i_idl_ota_service";
import {setDownloadTaskStatusCallback} from "./i_idl_ota_service";
import IIdlOtaService from "./i_idl_ota_service";
import rpc from "@ohos.rpc";

export default class IdlOtaServiceProxy implements IIdlOtaService {
    constructor(proxy) {
        this.proxy = proxy;
    }

    getCheckNewVersionStatus(callback: getCheckNewVersionStatusCallback): void
    {
        let _option = new rpc.MessageOption();
        let _data = new rpc.MessageParcel();
        let _reply = new rpc.MessageParcel();
        this.proxy.sendRequest(IdlOtaServiceProxy.COMMAND_GET_CHECK_NEW_VERSION_STATUS, _data, _reply, _option).then(function(result) {
            if (result.errCode === 0) {
                let _errCode = result.reply.readInt();
                if (_errCode != 0) {
                    let _returnValue = undefined;
                    callback(_errCode, _returnValue);
                    return;
                }
                let _returnValue = result.reply.readInt();
                callback(_errCode, _returnValue);
            } else {
                console.log("sendRequest failed, errCode: " + result.errCode);
            }
        })
    }

    setDownloadTaskStatus(status: number, callback: setDownloadTaskStatusCallback): void
    {
        let _option = new rpc.MessageOption();
        let _data = new rpc.MessageParcel();
        let _reply = new rpc.MessageParcel();
        _data.writeInt(status);
        this.proxy.sendRequest(IdlOtaServiceProxy.COMMAND_SET_DOWNLOAD_TASK_STATUS, _data, _reply, _option).then(function(result) {
            if (result.errCode === 0) {
                let _errCode = result.reply.readInt();
                callback(_errCode);
            } else {
                console.log("sendRequest failed, errCode: " + result.errCode);
            }
        })
    }

    static readonly COMMAND_GET_CHECK_NEW_VERSION_STATUS = 1;
    static readonly COMMAND_SET_DOWNLOAD_TASK_STATUS = 2;
    private proxy
}

